<?php

/**
 * 栏目列表
 *
 * @package    01CMS
 * @subpackage plugin
 * @author     rolong at vip.qq.com
 * @version    1.0.0
 * @link       http://www.01cms.com
 */

function smarty_block_category ($params, $content, $smarty, &$repeat)
{
    static $category = array();
    
    if (is_null($content))
    {
        $parentId = isset($params['parentId']) ? $params['parentId'] : 0;
        
        $category = model('Category')->getChildren($parentId);
    }
    if ($o = current($category))
    {
        if ($o->type > 0)
        {
            $o->activeUrl = BOOT_URL . '/data/category/' . $o->id;
            $o->staticUrl = ROOT_DIR . Base::i()->Load->var['htmlSaveDir'] . '/' . $o->alias;
            switch ($o->visit)
            {
                case 1:
                {
                    $o->url = $o->staticUrl;
                    break;
                }
                case 2:
                {
                    $o->url = $o->activeUrl;
                    break;
                }
                default:
                {
                    $o->url = defined('staticHtml') ? $o->staticUrl : $o->activeUrl;
                }
            }
        }
        else
        {
            $o->activeUrl = $o->staticUrl = $o->url = $o->link;
        }
        
        $smarty->assign('item', $o);
        
        next($category);
        
        $repeat = true;
    }
    else
    {
        $repeat = false;
    }
    
    return $content;
}